import 'package:flutter/material.dart';
import 'package:flutter_trip_demo/utils/navigator/navigator_util.dart';

import '../model/common_model.dart';
import 'my_webview.dart';


class LocalNav extends StatelessWidget {
  //设置全局变量
  final List<CommonModel> localNavList;

  const LocalNav({Key? key, required this.localNavList}) : super(key: key);

  Widget build(BuildContext context) {
    return Container(
      height: 64,
      decoration: const BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.all(Radius.circular(6)),
      ),
      child: Padding(
        padding: const EdgeInsets.all(7),
        child: _items(context),
      ),
    );
  }

  _items(BuildContext context) {

    if (localNavList == null) {
      return null;
    }
    List<Widget> items = [];
    localNavList.forEach((model) {
      items.add(_item(context, model));
    });
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: items,
    );
  }

  Widget _item(BuildContext context, CommonModel commonModel4) {
    return GestureDetector(
      onTap: () {
        //增加跳转功能
        NavigatorUtil.push(
          context,
          MyWebView(
            url: commonModel4.url,
            statusBarColor: commonModel4.statusBarColor,
            hideAppBar: commonModel4.hideAppBar,
          )
        );
      },
      child: Column(
        children: <Widget>[
          Image.network(
            commonModel4.icon,
            width: 32,
            height: 32,
          ),
          Text(
            commonModel4.title,
            style: const TextStyle(fontSize: 12),
          ),
        ],
      ),
    );
  }


}

